/**
 * @example
 * 

async function main(){
    let student = new ParseObject("Student")
    student.get().then(data=>{
        console.log(data)
    });


    let media = new ParseObject("BRBMedium");
    let list = await media.get()
    console.log(list)
    let data = await media.save({
        text:"我们通过ParseObject类进行保存的测试"
    })
    console.log(data)
}

main()

 */
export class ParseObject{
    className:string
    constructor(className:string){
        this.className = className
    }
    async get():Promise<any>{
        console.log("查询",this.className)
        let result = await fetch(`http://metapunk.cn:9999/parse/classes/${this.className}?`, {
        "headers": {
            "accept": "*/*",
            "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
            "if-none-match": "W/\"164-Qy3vijCmC7iE0mND19p6WsFbmSU\"",
            "x-parse-application-id": "dev"
        },
        "referrer": "http://localhost:4040/",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": null,
        "method": "GET",
        "mode": "cors",
        "credentials": "omit"
        });
        // {"results":[]}
        let data = await result.json();
        console.log(data)
        let list = data?.results
        return list
    }
    async save(body:any){
        console.log("保存",this.className)
        let jsonString = JSON.stringify(body)
        let result = await fetch(`http://metapunk.cn:9999/parse/classes/${this.className}`, {
        "headers": {
            "accept": "*/*",
            "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
            "content-type": "text/plain;charset=UTF-8",
            "x-parse-application-id": "dev"
        },
        "referrer": "http://localhost:4040/",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": jsonString,
        "method": "POST",
        "mode": "cors",
        "credentials": "omit"
        });
        let data = await result.json();
        console.log(data)
        return data
    }
    delete(){
        console.log("删除",this.className)
    }
}
